window.onload =()=>{
  let itemsDom = document.getElementById('items'),
      submitBtn = document.getElementById('submit');
  submitBtn.onclick = (e)=>{
    let item = document.getElementById('input');
    fetch('http://192.168.64.144:8080/todo',{method:'POST',body:'item'+item.value})
    .then(res=>{res.text().then(txt=>console.log(txt))});
  }
  fetch('http://192.168.64.144:8080/todo')
    .then(res=>{
      res.text()
      .then(
        txt=>{
          let items = JSON.parse(txt).data;
          itemsDom.innerHTML = items.map(item=>'<li>'+item+'</li>').join('\n');
          alert(items);
          console.log(txt)
        }
        )
    })
}
